<template>
	<view style="border-radius: 10rpx;margin: 10rpx;">
		<u--form
							labelPosition="left"
							:model="user"
							ref="form1"
					>
						<u-form-item 
								label="用户id:"
								borderBottom
								ref="item1"
						>
							<u--input
									:disabled="showUserId"
									v-model="user.userId"
									
									border="none" 
							></u--input>
						</u-form-item>
						<u-form-item
								label="密码:"
								borderBottom
								ref="item1"
						>
							<u--input
									v-model="user.password"
									border="none"
							></u--input>
						</u-form-item>
						<u-form-item
								label="用户名:"
								borderBottom
								ref="item1"
						>
							<u--input
									v-model="user.username"
									border="none"
							></u--input>
						</u-form-item>
						<u-form-item
								label="邮箱:"
								borderBottom
								ref="item1"
						>
							<u--input
									v-model="user.email"
									border="none"
							></u--input>
						</u-form-item>
						<u-form-item
								label="创建时间:"
								borderBottom
								ref="item1"
								v-show="user.createTime"
						>
							<u--input
									v-model="user.createTime"
									border="none"
							></u--input>
						</u-form-item>
					</u--form>
				</u--form>
				<u-button @click="insertMeeting" v-if="option_button===1" style="border-radius: 5%;width: 250rpx;background-color: #53C21D;margin-top: 80rpx;">添加</u-button>
				<u-button @click="updateMeeting" v-else style="border-radius: 5%;margin-top: 80rpx;width: 250rpx;background-color: #53C21D;">更新</u-button>
				
	</view>
</template>

<script>
	export default {
		data() {
			return {
				box1:true,
				user:'',
				subject:'',
				showUserId:false,
				option_button:2,
				time:''
			}
		},
		onLoad(options) {
			console.log(options.user)
			let str=options.user
			if(!str || 0 === str.length){
				this.option_button = 1
			}else{
				this.showUserId = true
				this.option_button = 2
				this.user  = JSON.parse(decodeURIComponent(options.user))
			}


		},
		methods: {
			updateMeeting(){
				uni.request({
					url:'/api/user/updateUser',
					method:'post',
					header:{
					            'content-type':'application/x-www-form-urlencoded'
					        },
					data:this.user,
					success: () => {
						uni.showToast({
										icon: 'success',
										position: 'bottom',
										title: '修改成功！'
									})
					},
					fail: (error) => {
						uni.showToast({
										icon: 'error',
										position: 'bottom',
										title: '修改失败！'+error
									})
					}
				})
				console.log(this.user)
			},
			handleReserve(){
				let data = {
				        meetingId: this.meeting.id,
				        subject: this.subject,
				        reserveTime: this.time.reserveTime,
				        reserverBegin: this.time.reserveBegin,
				        reserverEnd: this.time.reserveEnd,
						applyId:this.$store.getters.userinfo.userId
				      }
				uni.request({
					url:'/api/reserve/insertReserveInfo',
					method:'post',
					header:{
					            'content-type':'application/x-www-form-urlencoded'
					        },
					data:data,
					success: () => {
						uni.showToast({
										icon: 'success',
										position: 'bottom',
										title: '预约成功！'
									})
					},
					fail: (error) => {
						uni.showToast({
										icon: 'error',
										position: 'bottom',
										title: '预约失败！'+error
									})
					}
				})
			},
			getMeetingInfo(id){
				uni.request({
					url:'/api/meeting/getMeetingById?meetingId='+id,
					method:'get',
					success: (res) => {
						this.meeting = res.data.data
						console.log(res)
					}
				})
			}
			
		}
	}
</script>

<style>

</style>
